package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.OverflowList;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.service.OverFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author nzmxfan
 * @create 2021-09-05-0:42
 */
@RestController
@RequestMapping("/overflowListGoods")
public class OverFlowController {

    @Autowired
    OverFlowService overFlowService;

    /**
     * 新增报溢单
     * @param overflowList
     * @param overflowListGoodsStr
     * @param session
     * @return
     */
    @PostMapping("/save")
    public ServiceVO saveOverFlow(OverflowList overflowList, String overflowListGoodsStr, HttpSession session){

        // 从 session 域中获取当前用户
        User user = (User)session.getAttribute("currentUser");
        Integer userId = user.getUserId();
        overflowList.setUserId(userId);

        overFlowService.saveOverFlow(overflowList, overflowListGoodsStr);

        return new ServiceVO(100, "请求成功", null);
    }

    /**
     * 根据起止时间段查询报溢单
     * @param sTime
     * @param eTime
     * @return
     */
    @PostMapping("/list")
    public Map<String,Object> getDamageList(String sTime, String eTime){

        return overFlowService.getDamageList(sTime, eTime);
    }

    /**
     * 根据起止时间段查询报溢单
     * @param overflowListId
     * @return
     */
    @PostMapping("/goodsList")
    public Map<String,Object> goodsList(Integer overflowListId){

        return overFlowService.goodsList(overflowListId);
    }
}
